package com.orkcto.springcloude.hystrix;


import com.netflix.hystrix.HystrixCommand;
import org.springframework.web.client.RestTemplate;
//自定义的Hystrix  的降级熔断方法
public class MyHistrixCommand extends HystrixCommand<String> {

    private RestTemplate restTemplate;

    public MyHistrixCommand(Setter setter,RestTemplate restTemplate){
        super(setter);
        this.restTemplate = restTemplate;
    }

    @Override
    protected String run() throws Exception {
        //调用远程的服务
        return restTemplate.getForEntity("http://01-SPRING-CLOUD-SERVICE-PROVIDER/service/hello",String.class).getBody();

    }

    @Override
    public String getFallback() {
        //实现熔断服务降级的逻辑
        return  "error";
    }
}
